package org.example.net;

import lombok.SneakyThrows;

import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @Auther:Liu
 * @Testname:Get
 * @Date:2025/8/27 17:34
 */
public class Get extends Thread {
    @SneakyThrows
    public void run(String ip, int port) {
        Socket socket = new Socket(ip, port);
        System.out.println("通讯已开启");
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        while (true){
            int len = inputStream.read(bytes);
            String s = new String(bytes, 0, len, StandardCharsets.UTF_8);
            System.out.println(s);
            if ("bye".equals(s)) {
                break;
            }
        }
    }
}
